import React,{useState} from 'react'
import { NavBar, InputItem, Button, Toast } from "antd-mobile";
import {reqRegister} from "../../http/api"
import "./Register.less"
export default function Register(props) {
  const [user, setUser] = useState({
    phone: "",
    password: "",
    nickname: "",
  })
  const toRegister=()=>{
    reqRegister(user).then((res) => {
      if (res.data.code == 200) {
        Toast.info(res.data.msg,1);
        props.history.push("/login");
      }
    });
  }
  return (
    <div>
        <NavBar>注册页</NavBar>
        <InputItem
          placeholder="账号"
          onChange={(val) => setUser({...user,phone:val})}
        >
          账号
        </InputItem>
        <InputItem
          placeholder="昵称"
          onChange={(val) => setUser({...user,nickname:val})}
        >
          昵称
        </InputItem>
        <InputItem
          placeholder="密码"
          onChange={(val) => setUser({...user,password:val})}
        >
          密码
        </InputItem>
        <Button type="primary" className="but"  onClick={() => toRegister()}>
          注册
        </Button>
    </div>
  )
}
